﻿using System.Threading.Tasks;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using MaxStoreErp.Core.Exceptions;
using MaxStoreErp.Core.Interfaces;
using Microsoft.Practices.Unity;

namespace MaxStoreErp.Core.Infrastructure
{
    public class MetroProgressDialog : IProgressDialog
    {
        [Dependency]
        public IUnityContainer Container { get; set; }

        public async Task<IProgressDialogController> ShowProgressAsync(string message, string caption, bool isIndeterminated)
        {
            var shell = GetMetroWindow();
            var result = await shell.ShowProgressAsync(caption, message);
            return new MetroProgressDialogController(result);
        }

        MetroWindow GetMetroWindow()
        {
            var shellWindow = Container.Resolve<IShellWindow>().ShellView as MetroWindow;
            if (shellWindow == null)
                throw new ErpRuntimeException("Оболочка приложения не является окном Metro!");

            return shellWindow;
        }
    }
}
